﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <input type="hidden" id="goodsid" col="goodsid">
            <div class="select-list">
                <ul>
                    <li>
                        门店：<span id="shopid" col="shopid"></span>
                    </li>
                    @*<li>
                        分类：<span id="category_id" col="category_id"></span>
                    </li>
                    <li>
                        型号：<span id="goods_model_id" col="goods_model_id"></span>
                    </li>*@
                    <li>
                        商品名称：<input id="goods_name" col="goods_name" type="text" />
                    </li>
                    <li>
                        货物名称：<input id="name" col="name" type="text" />
                    </li>
                    <li>
                        货物颜色：<input id="color" col="color" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var goodsid = ys.request("goodsid");
    var name = ys.request("name");
    var goodsname = ys.request("goodsname");
    $(function () {

        $("#shopid").ysComboBox({
            url: '@Url.Content("~/QixingManage/Store/GetListJson")',
            key: "Id",
            value: "shop_name",
        });

        @*$("#category_id").ysComboBox({
            url: '@Url.Content("~/QixingManage/GoodsCategory/GetListJson")',
            key: "Id",
            value: "category_name",
        });

        $("#goods_model_id").ysComboBox({
            url: '@Url.Content("~/QixingManage/Models/GetListJson")',
            key: "Id",
            value: "model_name",
        });*@

        $("#goodsid").val(goodsid);

        if (goodsid != "null")
        {
            $("#goods_name").val(goodsname);
            $("#goods_name").attr("readonly", "true");
        }
        if (name !="null")
        {
            $("#color").val(name);
            $("#color").attr("readonly", "true");
        }

        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/StoreGoodsProduct/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'shop_name', title: '门店' },
                //{ field: 'category_name', title: '商品分类' },
                //{ field: 'goods_model_name', title: '商品型号',formatter: function (value, row, index) {
                //        if (!ys.isNullOrEmpty(row.goods_model_id)) {
                //            return value;
                //        }
                //    }
                //},
                { field: 'goods_name', title: '商品名称' },
                { field: 'VIN', title: '车架号' },
                { field: 'name', title: '货物名称' },
                { field: 'color', title: '货物颜色' },
                { field: 'in_cnt', title: '货物库存数' },
                { field: 'lock_cnt', title: '待付款货物数'},
                //{
                //    field: 'images', title: '货物封面', formatter: function (value, row, index) {
                //        if (index % 2 == 0) {
                //            return '<img class="img-circle img-xs" src="' + row.images + '" onclick=showImage("' + row.images + '") />';
                //        }
                //        else {
                //            return '<img class="img-circle img-xs" src="' + row.images + '" onclick=showImage("' + row.images + '") />';
                //        }
                //    }
                //},
                //{ field: 'model', title: '规格' },
                //{
                //    title: '操作',
                //    align: 'center',
                //    formatter: function (value, row, index) {
                //        var actions = [];
                //        actions.push('<a class="btn btn-info btn-xs" href="#" onclick="StorageForm(\'' + row.Id + '\',\'' + row.name + '\',\''+row.goods_id+'\')"><i class="fa fa-cart-plus"></i>货物入库</a> ');
                //        actions.push(' <a class="btn btn-danger btn-xs" href="#" onclick="StorageRecordList(\'' + row.Id + '\',\'' + row.name + '\')"><i class="fa fa-calendar"></i>入库记录</a>');
                //        return actions.join('');
                //    }
                //}

            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function StorageRecordList(id,name)
    {
         ys.openDialog({
            title:name+"->入库记录",
            width: '800px',
            height: '500px',
            content: '@Url.Content("~/QixingManage/GoodsStorageRecord/GoodsStorageRecordIndex")' + '?id=' + id,
            btn: [],
        });
    }

    function StorageForm(Id,name,gid)
    {
         ys.openDialog({
            title:name+'->入库',
             content: '@Url.Content("~/QixingManage/GoodsStorageRecord/GoodsStorageRecordForm")' + '?pid=' + Id + '&goodsid=' + gid,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }


    function showImage(imageUrl) {
        var html = '<img src="' + imageUrl + '" width="100%" height="100%" class="img-responsive" />';
        ys.openDialogContent({
            content: html,
            width: 'auto',
            height: 'auto',
            closeBtn: true
        });
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }

            if (ys.isNullOrEmpty(selectedRow[0].goods_model_id)) {
                   ys.msgError("请到商品列表绑定商品型号!");
                   return false;
            }
        }
        ys.openDialog({
            title: id > 0 ? '货物编辑' : '货物添加',
            content: '@Url.Content("~/QixingManage/StoreGoodsProduct/StoreGoodsProductForm")' + '?id=' + id + '&goodsid=' + goodsid,
            width: '968px',
            height: '650px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/StoreGoodsProduct/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
